home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 314 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.0 KB  |  92 lines

  1. Path: fido.asd.sgi.com!austern
  2. From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
  3. Newsgroups: comp.std.c++
  4. Subject: friend class declaration and nested classes
  5. Date: 07 Feb 1996 11:35:04 PST
  6. Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4fa71q$1rp@fsuj01.rz.uni-jena.de>
  9. Reply-To: mkt@isun04.inf.uni-jena.de
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 7 Feb 1996 12:47:54 GMT
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMRj/fky4NqrwXLNJAQETYQH/VhV1/6ZEeA/IfUSESHI17d0dt9jLZSUK
  14.     y16jXqc8i2hK92dJDiKxudMhmz4qlBz1bZbGgtiVV2v/0r2eOcH/Wg==
  15.     =jCmg
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. Consider this:
  19.  
  20.     class X;
  21.     
  22.     class Y {
  23.         class X {};
  24.         friend class ::X;  // error!!!
  25.     };
  26.  
  27. I meet that nice problem when compiling the following code:
  28.  
  29.     class A {
  30.         class B {};
  31.         friend class A::B;  // error!!!
  32.     };
  33.  
  34. Most compilers compile this without a warning. Only the one from
  35. DEC produced an 'invalid declarator' error.
  36.  
  37. I watched the ARM and found out:
  38.     Section 11.4: "... All the functions of a class X can be
  39.         made friends of a class Y by a single declaration
  40.         using an 'elaborated-type-specifier' ('9.1):
  41.  
  42.             class Y {
  43.                 friend class X;
  44.                 // ...
  45.             };"
  46.  
  47.     'elaborated-type-specifier':
  48.         'class-key' 'class-name'
  49.         'class-key' 'identifier'
  50.         enum 'enum-name'
  51.  
  52.     'class-key':
  53.         class
  54.         struct
  55.         union
  56.  
  57.     'class-name':
  58.         'identifier'
  59.  
  60. In what follows: The examples above are really errors!
  61. Correcting the second example is easy:
  62.  
  63.     class A {
  64.         class B {};
  65.         friend class B;
  66.     };
  67.  
  68. But how about the first example?!?!?!?
  69.  
  70.     class X;
  71.     
  72.     class Y {
  73.         class X {};
  74.         friend class X;  // That's not what I want!
  75.     class X;
  76.  
  77. Or:
  78.  
  79.     class X;
  80.     
  81.     class Y {
  82.         friend class X;  // Error: violating the rewriting rules!
  83.         class X {};
  84.     };
  85.  
  86. Bye.
  87. Tilo Koerbs,  mkt@uni-jena.de
  88. ---
  89. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  90.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  91.   in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
  92.